package com.model
{
	import mx.collections.ArrayCollection;
	
	public class Book_VO
	{
		private var _bookId:Number;
		private var _numOfPages:Number;
		private var _title:String;
		
		private var _bookPages:ArrayCollection = new ArrayCollection();
		
		public function Book_VO(bookId:Number, title:String, numOfPages:Number = 0)
		{
			_bookId = bookId;
			_numOfPages = numOfPages;
			_title = title;
		}
		
		/**
		 * Called in the setting of the model current book to creat the book pages. 
		 */		
		public function setupBook():void {
			_bookPages = new ArrayCollection();
			var page:InteractivePage;
			
			for(var i:int = 1; i < _numOfPages + 1; i++) {
				_bookPages.addItem(new InteractivePage(_bookId,i));
			}
		}
		/**
		 * Remove all pages to free the memory
		 * Called from setting the model current book, to free the previous book if exist 
		 */		
		public function freePages():void {
			_bookPages.removeAll();
			_bookPages = null;
		}
		
		[Bindable]
		public function get bookId():Number {
			return _bookId;
		}
		public function set bookId(val:Number):void {
			_bookId = val;
		}
		
		public function get numOfPages():Number {
			return _numOfPages;
		}
		public function set numOfPages(val:Number):void {
			_numOfPages = val;
		}
		
		public function get title():String{
			return _title;
		}
		public function set title(val:String):void {
			_title = val;
		}
		
		public function get bookPages():ArrayCollection {
			return _bookPages;
		}
		public function set bookPages(value:ArrayCollection):void { 
			_bookPages = value;
		}
	}
}